
$(function () {
    var address_id = parseInt(GetQueryString('address_id'));
    var payorder_id = parseInt(GetQueryString('payorder_id'));
    var html_data = {
        baseConfig: baseConfig,
        sessionid: '',
        sessionid_q: '',
        user_info:{},
        payorder_id: payorder_id,
        province_list:[],
        city_list:[],
        county_list:[],
        address_list: []

    };
    var app = new Vue({
        el: '#address_modefy',
        data: html_data,
        methods: {
            upload_file:function(){
                var file = document.getElementById("id_img_1");
                try {
                    var f = file.files[0]
                } catch (e) {
                    return
                }
                var rFilter = /^(image\/bmp|image\/gif|image\/jpeg|image\/png|image\/tiff)$/i;
                if (!rFilter.test(f.type)) {
                    alert("文件格式必须为图片");
                    return;
                }
                var vFD = new FormData(),    //建立请求和数据
                    oXHR = new XMLHttpRequest();
                vFD.append("sessionid", html_data.sessionid);
                vFD.append("file", f, "upload.jpg");
                oXHR.addEventListener('load', function (resUpload) {
                    //成功
                    get_user_info();
                    Magiclamp.mcAlert("提示", "修改头像成功。", null, function () {

                    });

                }, false);
                oXHR.addEventListener('error', function () {
                    //失败
                    Magiclamp.mcAlert("提示", "上传图片失败,请重新上传");
                }, false);
                oXHR.addEventListener('abort', function () {
                    //上传中断
                }, false);
                oXHR.open('POST', baseConfig.host + "/sys/update_userinfo_headimg");
                oXHR.send(vFD);
            },

            update_realname:function(){
                Magiclamp.mcPrompt("修改昵称", "请输入新昵称", function (data) {
                    api.sys.update_userinfo_realname({realname:data}).then(function (value) {
                        get_user_info();
                        Magiclamp.mcAlert("提示", "修改昵称成功。", null, function () {

                        });
                    })
                }, html_data.user_info.realname)
            },

            page_back: function () {
                baseConfig.page_back();
            }
        }
    });

    html_data.sessionid = GetQueryString('sessionid');
    if (html_data.sessionid) {
        html_data.sessionid_q = "sessionid=" + html_data.sessionid;
        client_storage('sessionid', html_data.sessionid);
    }else{
        html_data.sessionid = client_storage('sessionid');
    }
    
    var get_user_info = function () {
        api.sys.my_userinfo().then(function (data) {
            html_data.user_info = data.result;
        });
    }

    get_user_info();

});
